package com.zqc;

import java.util.Arrays;

public class LongKTest {
  private static void printLongK(int[] source, int k) {
    int[] dp = new int[source.length];
    Arrays.fill(dp, 1);
    for (int i = 1; i < source.length; i++) {
      if (source[i] > source[i - 1]) {
        dp[i] = dp[i - 1] + 1;
      }
    }
    printArray(dp);
    for (int i = 0; i < k; i++) {
      int maxLengthIndex = 0;
      for (int j = 0; j < dp.length; j++) {
        if (dp[j] > dp[maxLengthIndex]) {
          maxLengthIndex = j;
        }
      }
      int len = dp[maxLengthIndex];

      for (int j = maxLengthIndex - len+1; j < maxLengthIndex+1; j++) {
        System.out.print(source[j] + " ");
        dp[j]=1;
      }
      System.out.println("");
    }
  }

  private static void printArray(int[] ret) {
    for (int i = 0; i < ret.length; i++) {
      System.out.print(ret[i] + " ");
    }
    System.out.println("");
  }

  public static void main(String[] args) {
    int[] source = {3, 54, 64, 4, 6, 7, 8, 9, 4, 6,9};
    printLongK(source, 3);
  }
}
